#include "delge_squirrelgraphics_camera.h"

void s_Graphics_Camera_RegisterFunctions (HSQUIRRELVM v)
{
	SquirrelVM::CreateFunctionGlobal(s_Graphics_Camera_Create,						_SC("Camera_Create"),					_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_Camera_Destroy,						_SC("Camera_Destroy"),					_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_Camera_SetOrthographicProjection,	_SC("Camera_SetOrthographicProjection"),_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_Camera_SetPerspectiveProjection,	_SC("Camera_SetPerspectiveProjection"),	_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_Camera_SetViewport,					_SC("Camera_SetViewport"),				_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_Camera_GetViewportX,				_SC("Camera_GetViewportX"),				_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_Camera_GetViewportY,				_SC("Camera_GetViewportY"),				_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_Camera_GetViewportWidth,			_SC("Camera_GetViewportWidth"),			_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_Camera_GetViewportHeight,			_SC("Camera_GetViewportHeight"),		_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_Camera_SetPosition,					_SC("Camera_SetPosition"),				_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_Camera_GetPositionX,				_SC("Camera_GetPositionX"),				_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_Camera_GetPositionY,				_SC("Camera_GetPositionY"),				_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_Camera_GetPositionZ,				_SC("Camera_GetPositionZ"),				_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_Camera_SetScale,					_SC("Camera_SetScale"),					_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_Camera_GetScaleX,					_SC("Camera_GetScaleX"),				_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_Camera_GetScaleY,					_SC("Camera_GetScaleY"),				_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_Camera_GetScaleZ,					_SC("Camera_GetScaleZ"),				_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_Camera_SetPitch,					_SC("Camera_SetPitch"),					_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_Camera_SetYaw,						_SC("Camera_SetYaw"),					_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_Camera_SetRoll,						_SC("Camera_SetRoll"),					_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_Camera_GetPitch,					_SC("Camera_GetPitch"),					_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_Camera_GetYaw,						_SC("Camera_GetYaw"),					_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_Camera_GetRoll,						_SC("Camera_GetRoll"),					_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_Camera_Translate,					_SC("Camera_Translate"),				_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_Camera_Move,						_SC("Camera_Move"),						_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_Camera_Turn,						_SC("Camera_Turn"),						_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_Camera_Scale,						_SC("Camera_Scale"),					_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_Camera_SetBackgroundColor,			_SC("Camera_SetBackgroundColor"),		_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_camera_GetBackgroundColorRed,		_SC("Camera_GetBackgroundColorRed"),	_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_Camera_GetBackgroundColorGreen,		_SC("Camera_GetBackgroundColorGreen"),	_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_Camera_GetBackgroundColorBlue,		_SC("Camera_GetBackgroundColorBlue"),	_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_Camera_GetBackgroundColorAlpha,		_SC("Camera_GetBackgroundColorAlpha"),	_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_Camera_ProjectX,					_SC("Camera_ProjectX"),					_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Graphics_Camera_ProjectY,					_SC("Camera_ProjectY"),					_SC("*"));
}

SQInteger s_Graphics_Camera_Create (HSQUIRRELVM v)
{
	const SQChar		*sCameraName;
	SQInteger			iViewportX;
	SQInteger			iViewportY;
	SQInteger			iViewportWidth;
	SQInteger			iViewportHeight;

	sq_getstring		(v, 2, &sCameraName);
	sq_getinteger		(v, 3, &iViewportX);
	sq_getinteger		(v, 4, &iViewportY);
	sq_getinteger		(v, 5, &iViewportWidth);
	sq_getinteger		(v, 6, &iViewportHeight);

	Camera *pCamera = new Camera(iViewportX, iViewportY, iViewportWidth, iViewportHeight);

	ResourceManager<Camera>::LoadResource(sCameraName, pCamera);

	return 0;
}

SQInteger s_Graphics_Camera_Destroy (HSQUIRRELVM v)
{
	const SQChar		*sCameraName;

	sq_getstring		(v, 2, &sCameraName);

	ResourceManager<Camera>::UnloadResource(sCameraName);

	return 0;
}

SQInteger s_Graphics_Camera_SetOrthographicProjection (HSQUIRRELVM v)
{
	const SQChar		*sCameraName;
	SQFloat				fLeft, fRight;
	SQFloat				fTop, fBottom;
	SQFloat				fNear, fFar;

	sq_getstring		(v, 2, &sCameraName);
	sq_getfloat			(v, 3, &fLeft);
	sq_getfloat			(v, 4, &fRight);
	sq_getfloat			(v, 5, &fTop);
	sq_getfloat			(v, 6, &fBottom);
	sq_getfloat			(v, 7, &fNear);
	sq_getfloat			(v, 8, &fFar);

	Camera *pCamera = ResourceManager<Camera>::GetResource(sCameraName);

	pCamera->SetOrthographicProjection(fLeft, fRight, fTop, fBottom, fNear, fFar);

	return 0;
}

SQInteger s_Graphics_Camera_SetPerspectiveProjection (HSQUIRRELVM v)
{
	const SQChar		*sCameraName;
	SQFloat				fFieldOfView, fAspect;
	SQFloat				fNear, fFar;

	sq_getstring		(v, 2, &sCameraName);
	sq_getfloat			(v, 3, &fFieldOfView);
	sq_getfloat			(v, 4, &fAspect);
	sq_getfloat			(v, 5, &fNear);
	sq_getfloat			(v, 6, &fFar);

	Camera *pCamera = ResourceManager<Camera>::GetResource(sCameraName);

	pCamera->SetPerspectiveProjection(fFieldOfView, fAspect, fNear, fFar);

	return 0;
}

SQInteger s_Graphics_Camera_SetViewport (HSQUIRRELVM v)
{
	const SQChar		*sCameraName;
	SQInteger			iViewportX;
	SQInteger			iViewportY;
	SQInteger			iViewportWidth;
	SQInteger			iViewportHeight;

	sq_getstring		(v, 2, &sCameraName);
	sq_getinteger		(v, 3, &iViewportX);
	sq_getinteger		(v, 4, &iViewportY);
	sq_getinteger		(v, 5, &iViewportWidth);
	sq_getinteger		(v, 6, &iViewportHeight);

	Camera *pCamera = ResourceManager<Camera>::GetResource(sCameraName);

	pCamera->SetViewport(iViewportX, iViewportY, iViewportWidth, iViewportHeight);

	return 0;
}

SQInteger s_Graphics_Camera_GetViewportX (HSQUIRRELVM v)
{
	const SQChar		*sCameraName;

	sq_getstring		(v, 2, &sCameraName);

	Camera *pCamera = ResourceManager<Camera>::GetResource(sCameraName);

	sq_pushinteger		(v, pCamera->GetViewportX());

	return 1;
}

SQInteger s_Graphics_Camera_GetViewportY (HSQUIRRELVM v)
{
	const SQChar		*sCameraName;

	sq_getstring		(v, 2, &sCameraName);

	Camera *pCamera = ResourceManager<Camera>::GetResource(sCameraName);

	sq_pushinteger		(v, pCamera->GetViewportY());

	return 1;
}

SQInteger s_Graphics_Camera_GetViewportWidth (HSQUIRRELVM v)
{
	const SQChar		*sCameraName;

	sq_getstring		(v, 2, &sCameraName);

	Camera *pCamera = ResourceManager<Camera>::GetResource(sCameraName);

	sq_pushinteger		(v, pCamera->GetViewportWidth());

	return 1;
}

SQInteger s_Graphics_Camera_GetViewportHeight (HSQUIRRELVM v)
{
	const SQChar		*sCameraName;

	sq_getstring		(v, 2, &sCameraName);

	Camera *pCamera = ResourceManager<Camera>::GetResource(sCameraName);

	sq_pushinteger		(v, pCamera->GetViewportHeight());

	return 1;
}

SQInteger s_Graphics_Camera_SetPosition (HSQUIRRELVM v)
{
	const SQChar		*sCameraName;
	SQFloat				fX, fY, fZ;

	sq_getstring		(v, 2, &sCameraName);
	sq_getfloat			(v, 3, &fX);
	sq_getfloat			(v, 4, &fY);
	sq_getfloat			(v, 5, &fZ);

	Camera *pCamera = ResourceManager<Camera>::GetResource(sCameraName);

	pCamera->SetPosition(fX, fY, fZ);

	return 0;
}

SQInteger s_Graphics_Camera_GetPositionX (HSQUIRRELVM v)
{
	const SQChar		*sCameraName;

	sq_getstring		(v, 2, &sCameraName);

	Camera *pCamera = ResourceManager<Camera>::GetResource(sCameraName);

	sq_pushfloat		(v, pCamera->GetPositionX());

	return 1;
}

SQInteger s_Graphics_Camera_GetPositionY (HSQUIRRELVM v)
{
	const SQChar		*sCameraName;

	sq_getstring		(v, 2, &sCameraName);

	Camera *pCamera = ResourceManager<Camera>::GetResource(sCameraName);

	sq_pushfloat		(v, pCamera->GetPositionY());

	return 1;
}

SQInteger s_Graphics_Camera_GetPositionZ (HSQUIRRELVM v)
{
	const SQChar		*sCameraName;

	sq_getstring		(v, 2, &sCameraName);

	Camera *pCamera = ResourceManager<Camera>::GetResource(sCameraName);

	sq_pushfloat		(v, pCamera->GetPositionZ());

	return 1;
}

SQInteger s_Graphics_Camera_SetScale (HSQUIRRELVM v)
{
	const SQChar		*sCameraName;
	SQFloat				fScaleX, fScaleY, fScaleZ;

	sq_getstring		(v, 2, &sCameraName);
	sq_getfloat			(v, 3, &fScaleX);
	sq_getfloat			(v, 4, &fScaleY);
	sq_getfloat			(v, 5, &fScaleZ);

	Camera *pCamera = ResourceManager<Camera>::GetResource(sCameraName);

	pCamera->SetScale(fScaleX, fScaleY, fScaleZ);

	return 0;
}

SQInteger s_Graphics_Camera_GetScaleX (HSQUIRRELVM v)
{
	const SQChar		*sCameraName;

	sq_getstring		(v, 2, &sCameraName);

	Camera *pCamera = ResourceManager<Camera>::GetResource(sCameraName);

	sq_pushfloat		(v, pCamera->GetScaleX());

	return 1;
}

SQInteger s_Graphics_Camera_GetScaleY (HSQUIRRELVM v)
{
	const SQChar		*sCameraName;

	sq_getstring		(v, 2, &sCameraName);

	Camera *pCamera = ResourceManager<Camera>::GetResource(sCameraName);

	sq_pushfloat		(v, pCamera->GetScaleY());

	return 1;
}

SQInteger s_Graphics_Camera_GetScaleZ (HSQUIRRELVM v)
{
	const SQChar		*sCameraName;

	sq_getstring		(v, 2, &sCameraName);

	Camera *pCamera = ResourceManager<Camera>::GetResource(sCameraName);

	sq_pushfloat		(v, pCamera->GetScaleZ());

	return 1;
}

SQInteger s_Graphics_Camera_SetPitch (HSQUIRRELVM v)
{
	const SQChar		*sCameraName;
	SQFloat				fRotation;

	sq_getstring		(v, 2, &sCameraName);
	sq_getfloat			(v, 3, &fRotation);

	Camera *pCamera = ResourceManager<Camera>::GetResource(sCameraName);

	pCamera->SetPitch(fRotation);

	return 0;
}

SQInteger s_Graphics_Camera_SetYaw (HSQUIRRELVM v)
{
	const SQChar		*sCameraName;
	SQFloat				fRotation;

	sq_getstring		(v, 2, &sCameraName);
	sq_getfloat			(v, 3, &fRotation);

	Camera *pCamera = ResourceManager<Camera>::GetResource(sCameraName);

	pCamera->SetYaw(fRotation);

	return 0;
}

SQInteger s_Graphics_Camera_SetRoll (HSQUIRRELVM v)
{
	const SQChar		*sCameraName;
	SQFloat				fRotation;

	sq_getstring		(v, 2, &sCameraName);
	sq_getfloat			(v, 3, &fRotation);

	Camera *pCamera = ResourceManager<Camera>::GetResource(sCameraName);

	pCamera->SetRoll(fRotation);

	return 0;
}

SQInteger s_Graphics_Camera_GetPitch (HSQUIRRELVM v)
{
	const SQChar		*sCameraName;

	sq_getstring		(v, 2, &sCameraName);

	Camera *pCamera = ResourceManager<Camera>::GetResource(sCameraName);

	sq_pushfloat		(v, pCamera->GetPitch());

	return 1;
}

SQInteger s_Graphics_Camera_GetYaw (HSQUIRRELVM v)
{
	const SQChar		*sCameraName;

	sq_getstring		(v, 2, &sCameraName);

	Camera *pCamera = ResourceManager<Camera>::GetResource(sCameraName);

	sq_pushfloat		(v, pCamera->GetYaw());

	return 1;
}

SQInteger s_Graphics_Camera_GetRoll (HSQUIRRELVM v)
{
	const SQChar		*sCameraName;

	sq_getstring		(v, 2, &sCameraName);

	Camera *pCamera = ResourceManager<Camera>::GetResource(sCameraName);

	sq_pushfloat		(v, pCamera->GetRoll());

	return 1;
}

SQInteger s_Graphics_Camera_Translate (HSQUIRRELVM v)
{
	const SQChar		*sCameraName;
	SQFloat				fX, fY, fZ;

	sq_getstring		(v, 2, &sCameraName);
	sq_getfloat			(v, 3, &fX);
	sq_getfloat			(v, 4, &fY);
	sq_getfloat			(v, 5, &fZ);

	Camera *pCamera = ResourceManager<Camera>::GetResource(sCameraName);

	pCamera->Translate(fX, fY, fZ);

	return 0;
}

SQInteger s_Graphics_Camera_Move (HSQUIRRELVM v)
{
	const SQChar		*sCameraName;
	SQFloat				fX, fY, fZ;

	sq_getstring		(v, 2, &sCameraName);
	sq_getfloat			(v, 3, &fX);
	sq_getfloat			(v, 4, &fY);
	sq_getfloat			(v, 5, &fZ);

	Camera *pCamera = ResourceManager<Camera>::GetResource(sCameraName);

	pCamera->Move(fX, fY, fZ);

	return 0;
}

SQInteger s_Graphics_Camera_Turn (HSQUIRRELVM v)
{
	const SQChar		*sCameraName;
	SQFloat				fPitch, fYaw, fRoll;

	sq_getstring		(v, 2, &sCameraName);
	sq_getfloat			(v, 3, &fPitch);
	sq_getfloat			(v, 4, &fYaw);
	sq_getfloat			(v, 5, &fRoll);

	Camera *pCamera = ResourceManager<Camera>::GetResource(sCameraName);

	pCamera->Turn(fPitch, fYaw, fRoll);

	return 0;
}

SQInteger s_Graphics_Camera_Scale (HSQUIRRELVM v)
{
	const SQChar		*sCameraName;
	SQFloat				fScaleX, fScaleY, fScaleZ;

	sq_getstring		(v, 2, &sCameraName);
	sq_getfloat			(v, 3, &fScaleX);
	sq_getfloat			(v, 4, &fScaleY);
	sq_getfloat			(v, 5, &fScaleZ);

	Camera *pCamera = ResourceManager<Camera>::GetResource(sCameraName);

	pCamera->Scale(fScaleX, fScaleY, fScaleZ);

	return 0;
}

SQInteger s_Graphics_Camera_SetBackgroundColor (HSQUIRRELVM v)
{
	const SQChar		*sCameraName;
	SQInteger			iRed, iGreen, iBlue;
	SQInteger			iAlpha;

	sq_getstring		(v, 2, &sCameraName);
	sq_getinteger		(v, 3, &iRed);
	sq_getinteger		(v, 4, &iGreen);
	sq_getinteger		(v, 5, &iBlue);
	sq_getinteger		(v, 6, &iAlpha);

	Camera *pCamera = ResourceManager<Camera>::GetResource(sCameraName);

	pCamera->SetBackgroundColor(Color(iRed, iGreen, iBlue, iAlpha));

	return 0;
}

SQInteger s_Graphics_camera_GetBackgroundColorRed (HSQUIRRELVM v)
{
	const SQChar		*sCameraName;

	sq_getstring		(v, 2, &sCameraName);

	Camera *pCamera = ResourceManager<Camera>::GetResource(sCameraName);

	sq_pushinteger		(v, pCamera->GetBackgroundColor()[0]);

	return 1;
}

SQInteger s_Graphics_Camera_GetBackgroundColorGreen (HSQUIRRELVM v)
{
	const SQChar		*sCameraName;

	sq_getstring		(v, 2, &sCameraName);

	Camera *pCamera = ResourceManager<Camera>::GetResource(sCameraName);

	sq_pushinteger		(v, pCamera->GetBackgroundColor()[1]);

	return 1;
}

SQInteger s_Graphics_Camera_GetBackgroundColorBlue (HSQUIRRELVM v)
{
	const SQChar		*sCameraName;

	sq_getstring		(v, 2, &sCameraName);

	Camera *pCamera = ResourceManager<Camera>::GetResource(sCameraName);

	sq_pushinteger		(v, pCamera->GetBackgroundColor()[2]);

	return 1;
}

SQInteger s_Graphics_Camera_GetBackgroundColorAlpha (HSQUIRRELVM v)
{
	const SQChar		*sCameraName;

	sq_getstring		(v, 2, &sCameraName);

	Camera *pCamera = ResourceManager<Camera>::GetResource(sCameraName);

	sq_pushinteger		(v, pCamera->GetBackgroundColor()[2]);

	return 1;
}

SQInteger s_Graphics_Camera_ProjectX (HSQUIRRELVM v)
{
	const SQChar		*sCameraName;
	SQFloat				fX;
	SQInteger			iScreenWidth, iScreenHeight;

	sq_getstring		(v, 2, &sCameraName);
	sq_getfloat			(v, 3, &fX);
	sq_getinteger		(v, 4, &iScreenWidth);
	sq_getinteger		(v, 5, &iScreenHeight);

	Camera *pCamera = ResourceManager<Camera>::GetResource(sCameraName);

	sq_pushfloat		(v, pCamera->Project2D(Vector3(fX, 0, 0), iScreenWidth, iScreenHeight)[0]);

	return 1;
}

SQInteger s_Graphics_Camera_ProjectY (HSQUIRRELVM v)
{
	const SQChar		*sCameraName;
	SQFloat				fY;
	SQInteger			iScreenWidth, iScreenHeight;

	sq_getstring		(v, 2, &sCameraName);
	sq_getfloat			(v, 3, &fY);
	sq_getinteger		(v, 4, &iScreenWidth);
	sq_getinteger		(v, 5, &iScreenHeight);

	Camera *pCamera = ResourceManager<Camera>::GetResource(sCameraName);

	sq_pushfloat		(v, pCamera->Project2D(Vector3(0, fY, 0), iScreenWidth, iScreenHeight)[1]);

	return 1;
}